<template>
	<view>
		<view style="height: 250rpx; margin: 40rpx ; margin-top: 140rpx;" class="grid-item-box">
			<image mode="widthFix" style="width: 40%; align-items: center;" src="../../static/icon/技街图标.png" ></image>
			
		</view>
		<view style="margin: 50rpx ;">
			<view style="font-size: 44rpx;text-align: center; font-weight: bold;margin-bottom: 20rpx;">技大堕落街商家管理端</view>
			<uni-easyinput v-model="username" placeholder="请输入用户名" prefix-icon="person"></uni-easyinput>
			<uni-easyinput type="password" v-model="password" placeholder="请输入密码" prefix-icon="person"></uni-easyinput>
			<view style="font-size: 35rpx;color: #a1a1a1;">
				<checkbox :checked="rememberPassword" color="#FFCC33" style="transform:scale(0.7)" @click="changeRemember()" />记住密码
			</view>
			<button type="primary" style="background-color:#fdcd1c; margin: 60rpx 10rpx; border-radius: 60rpx;" @click="login()">登录</button>
		</view>
	</view>
</template>

<script>
import { adminBaseUrl } from '../../config/config'
	export default {
		data() {
			return {
				username: '',
				password: '',
				rememberPassword: false,
			}
		},
		onShow() {
			let username=uni.getStorageSync('empUsername')
			let password=uni.getStorageSync('empPassword')
			let rememberPassword=uni.getStorageSync('rememberPassword')
			if(rememberPassword!=void 0&&rememberPassword!=null){
				this.rememberPassword=rememberPassword
			}
			if(username!=void 0&&username!=null){
				this.username=username
			}
			if(password!=void 0&&password!=null&&this.rememberPassword==true){
				this.password=password
			}
		},
		methods: {
			login(){
				uni.request({
					url:adminBaseUrl+'/employee/login',
					method:'POST',
					data:{
						username: this.username,
						password: this.password
					},
					success: (res) => {
						//console.log(res)
						if(res.data.code==1){
							let empToken= res.data.data.token
							uni.setStorageSync('empToken',empToken)
							uni.redirectTo({
								url: '/pages/employee/employee'
							})
						}
						// else{
						// 	uni.showModal({
						// 		title: res.data.msg,
						// 		showCancel: false,
						// 		confirmColor:'#fad412'
						// 	})
						// }
					}
					
				})
				uni.setStorageSync('rememberPassword',this.rememberPassword)
				uni.setStorageSync('empUsername',this.username)
				if(this.rememberPassword==true)
					uni.setStorageSync('empPassword',this.password)
			},
			changeRemember(){
				this.rememberPassword=!this.rememberPassword
			}
		}
	}
</script>

<style>
.grid-item-box {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}
</style>
